﻿using SuperX.Common;
using System;
using System.Collections.Generic;
using System.Text;

namespace SuperX.DataService.Abstract
{
    //历史数据、报警数据的提交和数据均从服务器
    public interface IHDAServer : IDisposable
    {
    }

    public interface IDataServer : IDisposable, IBasicObject
    {
        IIOTag IndexFind(long id);

        IIOTag NameFind(string name);

        Object SyncRoot { get; }//对所有涉及集合更改项目使用；包括IGROUP的ADDITEMS
        IList<TagConfig> MetaDataList { get; }
        IList<Scaling> ScalingList { get; }
        IEnumerable<IDriver> Drivers { get; }

        IEnumerable<string> BrowseItems(BrowseType browseType, string tagName, DataType dataType);

        IDriver AddDriver(string name, string nodeName, string assembly, string className, Dictionary<string, ArgumentModel> argument);

        IGroup GetGroupByName(string name);

        int GetScaleByID(long id);

        int GetItemProperties(long id);//返回的是元数据在元数据列表的索引

        bool RemoveDriver(IDriver device);

        bool AddItemIndex(string key, IIOTag value);

        bool RemoveItemIndex(string key);

        void ActiveItem(bool active, params IIOTag[] items);
    }

    public class FCTCOMMAND
    {
        public const byte fctHead = 0xAB;//报头可加密，如报头不符，则不进行任何操作；客户端Socket发送报警请求，封装于Server
        public const byte fctHdaIdRequest = 30;
        public const byte fctHdaRequest = 31;
        public const byte fctAlarmRequest = 32;
        public const byte fctOrderChange = 33;
        public const byte fctReset = 34;
        public const byte fctXMLHead = 0xEE;//xml协议
        public const byte fctReadSingle = 1;
        public const byte fctReadMultiple = 2;
        public const byte fctWriteSingle = 5;
        public const byte fctWriteMultiple = 15;
    }

    public enum HDAAggregate
    {
        HDANoAggregate,
        HDAInterpolative,
        HDATotal,
        HDAAverage,
        HDATimeAverage,
        HDACount,
        HDAStDev,
        HDAMinimumActualTime,
        HDAMinimum,
        HDAMaximumActualTime,
        HDAMaximum,
        HDAStart,
        HDAEnd,
        HDADelta,
        HDARegSlope,
        HDARegConst,
        HDARegDev,
        HDAVariance,
        HDARange,
        HDADurationGood,
        HDADurationBad,
        HDAPercentGood,
        HDAPercentBad,
        HDAWorstQuality,
        HDAAnnotations,
    }

    public enum BrowseType
    {
        Branch = 1,
        Leaf = 2,
        Flat = 3
    }
}